package me.cjj.android.assignment

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    fun Context.startQuizActivity() =
            Intent(this, QuizActivity::class.java).let(this::startActivity)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.btn_start_quiz)
                .setOnClickListener({
                    if (etStudentName.text.isEmpty() || etStudentId.text.isEmpty()) {
                        Toast.makeText(this@MainActivity, "Please input name and id", Toast.LENGTH_LONG).show()
                        return@setOnClickListener;
                    }
                    startQuizActivity()
                    finish()
                })
    }
}
